//
//  main.cpp
//  ThreadPoolTest
//
//  Created by huge on 2021/6/23.
//  Copyright © 2021 huge. All rights reserved.
//

//https://www.cnblogs.com/ailumiyana/p/10016965.html


#include <iostream>
#include <chrono>
#include <condition_variable>
#include "thread_pool.hpp"

#include "easylogging++.h"


std::mutex g_mutex;

void priorityFunc()
{
    for (int i = 1; i < 4; ++i)
    {
        std::this_thread::sleep_for(std::chrono::seconds(1));
        std::lock_guard<std::mutex> lock(g_mutex);
        LOG(INFO) << "priorityFunc() [" << i << "] at thread [ " << std::this_thread::get_id() << "] output" << std::endl;
    }
    
}

void testFunc()
{
    // loop to print character after a random period of time
    for (int i = 1; i < 4; ++i)
    {
        std::this_thread::sleep_for(std::chrono::seconds(1));
        std::lock_guard<std::mutex> lock(g_mutex);
        LOG(INFO) << "testFunc() ["     << i << "] at thread [ " << std::this_thread::get_id() << "] output" << std::endl;
    }
    
}


int main(int argc, const char * argv[]) {
    // insert code here...

    LOG(INFO) << "My first info log using default logger";

    huge::thread_pool thread_pool;

    for(int i = 0; i < 5 ; i++)
         thread_pool.add_job_withPara(testFunc, false);

    thread_pool.add_job_withPara(priorityFunc, true);

    getchar();
    return 0;
    

}
